package cn.lsnu.modules.watch.service;

import cn.lsnu.common.interfacetools.interfaceentity.Page;
import cn.lsnu.common.interfacetools.interfaceservice.BaseService;
import cn.lsnu.modules.watch.entity.GaspaymentEntity;
import cn.lsnu.modules.watch.entity.WatchTaskEntity;
import cn.lsnu.modules.watch.mapper.WatchTaskMapper;
import cn.lsnu.utils.Guuid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class WatchTaskService extends BaseService<WatchTaskEntity,WatchTaskMapper> {

    @Autowired
    private WatchTaskMapper watchTaskMapper;


    @Override
    public void save(WatchTaskEntity entity) throws Exception {
        entity.setTaskId(Guuid.uuid());
        entity.setStatus("0");
        entity.setTaskTime(new Date());
        super.save(entity);
    }

    @Override
    public WatchTaskEntity get(String key) throws Exception {
        return super.get(key);
    }

    @Override
    public WatchTaskEntity getEntity(WatchTaskEntity entity) throws Exception {
        return super.getEntity(entity);
    }

    @Override
    public List<WatchTaskEntity> findList(WatchTaskEntity entity) throws Exception {
        return super.findList(entity);
    }

    @Override
    public Page<WatchTaskEntity> findPage(WatchTaskEntity entity) throws Exception {
        return super.findPage(entity);
    }

    @Override
    public void delete(WatchTaskEntity entity) throws Exception {
        super.delete(entity);
    }

    @Override
    public void update(WatchTaskEntity entity) throws Exception {
        super.update(entity);
    }

    public List<WatchTaskEntity> addressCount(WatchTaskEntity entity)throws Exception{
        entity.setTaskTime(entity.getTaskTime() == null ?new Date():entity.getTaskTime());
        return watchTaskMapper.addressCount(entity);
    }

    public void updateStatus(GaspaymentEntity entity)throws Exception{
//        entity.setReadDate(new Date());
        watchTaskMapper.updateStatus(entity);
    }
}
